﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.SqlClient;

namespace ERPStore.Diagnostics.Repositories
{
	public class DiagnosticDbContext : DbContext
	{
		public DiagnosticDbContext()
			: this("name = ERPStoreConnectionString")
		{

		}

		public DiagnosticDbContext(string connectionString)
			: base(connectionString)
		{
			var csBuilder = new SqlConnectionStringBuilder(this.Database.Connection.ConnectionString);
			csBuilder.ApplicationName = this.GetType().Assembly.FullName + "," + System.Environment.MachineName;
			this.Database.Connection.ConnectionString = csBuilder.ConnectionString;

			Configuration.LazyLoadingEnabled = false;
			Configuration.ProxyCreationEnabled = false;
		}

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			modelBuilder.Configurations.Add(new Mapping.RewriteUrlMap());
		}


	}
}
